//---------------------------------------------------------------------------

#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <DBGrids.hpp>
#include <Grids.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include "frxClass.hpp"
#include "frxDBSet.hpp"
#include "frxExportPDF.hpp"
#include "frxExportRTF.hpp"
#include "frxExportXLS.hpp"
//---------------------------------------------------------------------------
class TMotorControl : public TForm
{
__published:    // IDE-managed Components
    TTimer *PollingTimer;
    TPageControl *PageCtrl;
    TTabSheet *DisplayPage;
    TTabSheet *SettingPage;
    TGroupBox *Disp;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    TComboBox *ModelCb;
    TEdit *TargetEd;
    TEdit *RunTimeEd;
    TEdit *LostTimeEd;
    TLabel *Label5;
    TLabel *OverTimeLb;
    TLabel *Label6;
    TGroupBox *SettingGroupBt;
    TButton *NewBt;
    TButton *DeleteBt;
    TButton *ActiveBt;
    TButton *ReportBt;
    TButton *ChangePassBt;
    TGroupBox *SettingGroupGird;
    TDBGrid *DBGrid;
    TADOConnection *ADOCon;
    TADOTable *ModelADO;
    TADOTable *PassADO;
    TDataSource *DataSource;
	TButton *StartBt;
	TButton *StopBt;
	TButton *TargetAdjBt;
	TLabel *AdjTargetLb;
	TTrackBar *SpeedCtrl;
	TLabel *lbl1;
	TEdit *StandardSpeedEd;
	TEdit *ActualSpeedEd;
	TLabel *lbl2;
	TLabel *Label7;
	TLabel *Label8;
	TLabel *Label9;
	TTimer *RunCountTimer;
	TTimer *LostCountTimer;
	TfrxRTFExport *frxRTFExport1;
	TfrxXLSExport *frxXLSExport1;
	TfrxPDFExport *frxPDFExport1;
	TfrxReport *frReport;
	TfrxDBDataset *frDBDataset;
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall SendClick(TObject *Sender);
    void __fastcall PollingTimerTimer(TObject *Sender);
	void __fastcall FormResize(TObject *Sender);
    void __fastcall SpeedCtrlChange(TObject *Sender);
	void __fastcall TargetAdjBtClick(TObject *Sender);
    void __fastcall SpeedCtrlExit(TObject *Sender);
    void __fastcall PageCtrlChange(TObject *Sender);

    void __fastcall InsertRecord(String iModel, String iTarget, String iOT, String iStartTime, String iStopTime, String iDate);
	void __fastcall GetModelItem(void);
    void __fastcall LoadModel(void);
 	//void __fastcall SaveModel(String iModel);
	//void __fastcall Run(void);
	//void __fastcall Stop(void);
	//void __fastcall Pause(void);

	void __fastcall NewBtClick(TObject *Sender);
	void __fastcall StartBtClick(TObject *Sender);
	void __fastcall StopBtClick(TObject *Sender);
	void __fastcall DeleteBtClick(TObject *Sender);
	void __fastcall ChangePassBtClick(TObject *Sender);
	void __fastcall ActiveBtClick(TObject *Sender);
	void __fastcall ModelCbChange(TObject *Sender);
	void __fastcall RunCountTimerTimer(TObject *Sender);
	void __fastcall LostCountTimerTimer(TObject *Sender);
	void __fastcall ReportBtClick(TObject *Sender);

private:    // User declarations
public:     // User declarations
    __fastcall TMotorControl(TComponent* Owner);
	bool        s_AdjEnable;
    TADOTable	*pPassADO;
};

#define COM1    1
#define COM2    2
#define COM3    3

#define TIME_WORK 		430
#define TIME_OT 		170
#define	EFFICIENCY		90

#define STEP_PER_ROUND  16530

#define COMPORT         COM1
#define DIFF_STEP       3
#define FREQ_INC        5
#define SAMPLE_TIME     1000

#define ENCODER_ADDRESS         0x80

#define NULL_CMD            0
#define GET_STATUS_CMD      's'
#define SET_SAMPLE_TIMER    't'

#define ON_STATUS   0x80
#define OFF_STATUS  0x40

#define MOTOR_READ_4COIL_CMD    0x01
#define MOTOR_WRITE_1COIL_CMD   0x05

#define MOTOR_READ_8REG_CMD     0x03
#define MOTOR_WRITE_1REG_CMD    0x06
#define MOTOR_WRITE_8REG_CMD    0x10

#define TURN_ON_MOTOR1_CMD      0x80
#define TURN_ON_MOTOR2_CMD      0x81
#define TURN_OFF_MOTOR1_CMD     0x82
#define TURN_OFF_MOTOR2_CMD     0x83
#define SET_SPEED_MOTOR1_CMD    0x84
#define SET_SPEED_MOTOR2_CMD    0x85

//---------------------------------------------------------------------------
extern PACKAGE TMotorControl *MotorControl;
//---------------------------------------------------------------------------
#endif
